import React            from 'react';
import {connect}        from "react-redux";

import {Active}         from './Active';
import {
    ident,
    userInfo,
    distinct,
    activeEdit,
}                       from "../../actions/active";
import Nav from "../../config/Navigator";

class ActiveEdit extends Active {

    _distinct = {};
    saveText = '保存';

    componentWillMount(){
        document.title = '修改会员';
        this.props.userInfo().then(r => {
            this.setState(this.info = r);
        });
    }

    preIdent(phone){
        return this.info.phone === phone ? Promise.resolve(true) :
            this.props.distinct(phone).then(() => true).catch(() => {
                this.alert('手机号重复');
                return false;
            });
    }

    save(){
        if(!this.saving && this._check() === true){
            this.saving = true;
            this.props.activeEdit(this.state).then(r => {
                this.alert('修改成功');
                this.saving = false;
                this.router.push(Nav.auth('voucher'));
            });
        }
    }

}

export default connect(undefined, {ident, distinct, activeEdit, userInfo})(ActiveEdit);
